#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template import plot_template
from plot_template_combined import plot_template_combined

###############
## Plotting ###
###############
RatioSize=-0.2
RatioErr=1
RatioMin,RatioMax=0.5,1.5
RatioAdj=-1

ShowMCErr=-1
MCErree=0.03157
MCErrmm=0.01276
MCErrll=0.01584

plot_config='plot_configure'

histoDir='NOM'

#ATLAS='ATLAS For Approval'
ATLAS=''
figFormat='all'

yscale=2

####### Quad, MZ1
Xmin, Xmax=60, 120
Rebin=5
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_Quad_MZ1'
hxt='m_{Z1}^{eeee} [GeV]'
MCErr=MCErree
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_Quad_MZ1'
hxt='m_{Z1}^{ee#mu#mu} [GeV]'
MCErr=MCErrmm
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_Quad_MZ1'
hxt='m_{Z1}^{#mu#muee} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_Quad_MZ1'
hxt='m_{Z1}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_Quad_MZ1'
hxt='m_{Z1} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### Quad, MZ2
Xmin, Xmax=60, 120
Rebin=5
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_Quad_MZ2'
hxt='m_{Z2}^{eeee} [GeV]'
MCErr=MCErree
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_Quad_MZ2'
hxt='m_{Z2}^{ee#mu#mu} [GeV]'
MCErr=MCErrmm
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_Quad_MZ2'
hxt='m_{Z2}^{#mu#muee} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_Quad_MZ2'
hxt='m_{Z2}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_Quad_MZ2'
hxt='m_{Z2} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### Quad, MZZ
Xmin, Xmax=100, 500
Rebin=20
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_Quad_MZZ'
hxt='m_{ZZ}^{eeee} [GeV]'
MCErr=MCErree
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_Quad_MZZ'
hxt='m_{ZZ}^{ee#mu#mu} [GeV]'
MCErr=MCErrmm
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_Quad_MZZ'
hxt='m_{ZZ}^{#mu#muee} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_Quad_MZZ'
hxt='m_{ZZ}^{#mu#mu#mu#mu} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_Quad_MZZ'
hxt='m_{ZZ} [GeV]'
MCErr=MCErrll
plot_template(hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

